import React, { useState } from 'react';
import { Form, Input, Button, message } from 'antd';
import { MailOutlined } from '@ant-design/icons';
import { Link } from 'react-router-dom';
import styles from './index.module.css';

const ForgotPassword: React.FC = () => {
  const [loading, setLoading] = useState(false);

  const onFinish = async (values: any) => {
    try {
      setLoading(true);
      // TODO: 调用重置密码接口
      console.log('重置密码:', values);
      message.success('重置密码邮件已发送，请查收');
    } catch (error) {
      message.error('重置密码失败，请重试');
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className={styles.container}>
      <div className={styles.content}>
        <h2>重置密码</h2>
        <Form
          name="forgot-password"
          onFinish={onFinish}
          autoComplete="off"
          layout="vertical"
        >
          <Form.Item
            name="email"
            rules={[
              { required: true, message: '请输入邮箱' },
              { type: 'email', message: '请输入有效的邮箱地址' }
            ]}
          >
            <Input
              prefix={<MailOutlined />}
              placeholder="请输入邮箱"
              size="large"
            />
          </Form.Item>

          <Form.Item>
            <Button type="primary" htmlType="submit" loading={loading} block size="large">
              发送重置邮件
            </Button>
          </Form.Item>

          <div className={styles.links}>
            <Link to="/login">返回登录</Link>
          </div>
        </Form>
      </div>
    </div>
  );
};

export default ForgotPassword;